package com.googlecode.antilopebpm.context;

import org.hibernate.*;
import org.hibernate.cfg.Configuration;

import com.googlecode.antilopebpm.variable.converter.SerializableToByteArrayConverter;
import com.googlecode.antilopebpm.variable.instance.reference.ByteArray;

public class Main {
	public static void main(String[] args) {
		Configuration config = new Configuration().setProperty(
				"hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
				.setProperty("hibernate.connection.driver_class",
						"com.mysql.jdbc.Driver").setProperty(
						"hibernate.connection.url", "jdbc:mysql:///antilope")
				.setProperty("hibernate.connection.username", "root")
				.setProperty("hibernate.connection.password", "").setProperty(
						"hibernate.connection.pool_size", "1").setProperty(
						"hibernate.connection.autocommit", "true").setProperty(
						"hibernate.cache.provider_class",
						"org.hibernate.cache.HashtableCacheProvider")
				.setProperty("hibernate.hbm2ddl.auto", "create-drop")
				.setProperty("hibernate.show_sql", "true").addClass(
						ByteArray.class);

		SessionFactory sessionFactory = config.buildSessionFactory();
		Session session = sessionFactory.openSession();

		Foo foo = new Foo();
		foo.setName("2");
		SerializableToByteArrayConverter stb = new SerializableToByteArrayConverter();

		ByteArray byteArray = new ByteArray(stb.convert(foo));

		session.save(byteArray);

		session.flush();

		ByteArray byteArray2 = (ByteArray) session.createQuery(
				"from com.googlecode.antilopebpm.context.variable.ByteArray")
				.list().get(0);
		Foo fo2 = (Foo) stb.revert(byteArray2);
		System.out.println(fo2.getName());
	}
}
